<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Welcome extends CI_Controller {

    private $smarty;

    public function __construct() {
        parent::__construct();
        require_once 'smartyLoader.php';
        $this->smarty = $smarty;
    }

    public function index() {

        $this->smarty->assign("templateActivo", "inicial.tpl.html");
        $this->root();
    }

    private function root() {
        $this->setAssigns();
        $this->smarty->display('header.tpl.html');
        $this->smarty->display('main.tpl.html');
        $this->smarty->display('footer.tpl.html');
    }

    private function setAssigns() {
        if ($this->user->isAdmin()) {
            $this->smarty->assign("isAdmin", 1);
        } else {
            $this->smarty->assign("isAdmin", 0);
        }

        if ($this->user->isValidUser()) {
            $this->smarty->assign("isValidUser", 1);
        } else {
            $this->smarty->assign("isValidUser", 0);
        }


        $utilizador = $this->session->all_userdata();
        if (isset($utilizador['utilizador'])) {
            $user = $utilizador['utilizador'];
        } else {
            $user = '';
        }
        $this->smarty->assign("nomeAdmin", $user);
    }

    public function regulamento() {

        $this->smarty->assign("templateActivo", "inicial_regulamento.tpl.html");
        $this->root();
    }

    public function objetivos() {
        $this->smarty->assign("templateActivo", "inicial_objetivos.tpl.html");
        $this->root();
    }

    public function problemas() {
        $this->smarty->assign("templateActivo", "inicial_problemas.tpl.html");
        $this->root();
    }

    public function listaequipas() {

        
        $this->load->model('equipaModel');
        $equipas = $this->equipaModel->loadAll();
        
        $this->smarty->assign("equipas", $equipas);
        
        $this->smarty->assign("templateActivo", "inicial_listaequipas.tpl.html");
        $this->root();
    }

    public function correio() {
        $this->smarty->assign("templateActivo", "inicial_correio.tpl.html");
        $this->root();
    }

}
